package com.farmpost.server.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.farmpost.server.pojo.Resource;
import com.farmpost.server.pojo.RespBean;
import com.farmpost.server.service.IResourceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 资源表 前端控制器
 * </p>
 *
 * @author king
 * @since 2022-05-03
 */
@RestController
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    private IResourceService iResourceService;

    @ApiOperation(value = "推荐资源")
    @PutMapping("/insertResource")
    public RespBean insertResource(@RequestBody Resource resource) {
        return iResourceService.insertResource(resource);
    }

    @ApiOperation(value = "编辑资源")
    @PostMapping("/updateResource")
    public RespBean updateResource(@RequestBody Resource resource) {
        return iResourceService.updateResource(resource);
    }

    @ApiOperation(value = "删除资源")
    @DeleteMapping("/deleteResource")
    public RespBean deleteResource(@RequestBody Integer id) {
        return iResourceService.deleteResource(id);
    }

    @ApiOperation(value = "查看资源")
    @GetMapping("/getResources")
    public List<Resource> getResources(@RequestParam Integer page) {
        Page<Resource> resourcePage = new Page<Resource>(page,20, false);
        return iResourceService.getResources(resourcePage);
    }

}
